package ProductionConsumption;

/**
 * @Author mao
 * @Date 2025/11/22
 * @Description 消费者类
 */
public class Consumer implements Runnable {
    private Supermarket supermarket;
    private int id;

    public Consumer(Supermarket supermarket, int id) {
        this.supermarket = supermarket;
        this.id = id;
    }

    @Override
    public void run() {
        try {
            for (int i = 0; i < 15; i++) {
                supermarket.consume(id);
                Thread.sleep(300); // 模拟购物耗时
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
}
